/*
 * RunJavaScriptCodeAction.java
 *
 * Created on 2010-05-25, 21:20:28
 */

package JET.Frames.actionframe.actionpanels;

import JET.Actions.Action;
import JET.Actions.RunJavaScriptCodeAction;
import JET.Centers.ControlCenter;
import JET.StaticActions;

/**
 *
 * @author 057Ry
 */
public class RunJavaScriptCodeActionPanel extends javax.swing.JPanel {

    static final ControlCenter CC = ControlCenter.getInstance();

    /** Creates new form RunJavaScriptCodeAction */
    public RunJavaScriptCodeActionPanel() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        codeTextArea = new javax.swing.JTextArea();
        buildActionButton = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        nameTextField = new javax.swing.JTextField();

        setPreferredSize(new java.awt.Dimension(323, 306));

        jLabel1.setText("Enter Java Script code here :");

        codeTextArea.setColumns(20);
        codeTextArea.setRows(5);
        jScrollPane1.setViewportView(codeTextArea);

        buildActionButton.setText("Build action and add to action list");
        buildActionButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buildActionButtonActionPerformed(evt);
            }
        });

        jLabel2.setText("Name :");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addContainerGap(176, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addGap(28, 28, 28)
                        .addComponent(nameTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 254, Short.MAX_VALUE))))
            .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 326, Short.MAX_VALUE)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(buildActionButton, javax.swing.GroupLayout.DEFAULT_SIZE, 306, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(nameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 198, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(buildActionButton)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void buildActionButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buildActionButtonActionPerformed
        String name = nameTextField.getText();
        String code = codeTextArea.getText();
        Action action = new RunJavaScriptCodeAction(name, code, CC.getCurrentScene());
        StaticActions.addAction(action);
    }//GEN-LAST:event_buildActionButtonActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton buildActionButton;
    private javax.swing.JTextArea codeTextArea;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextField nameTextField;
    // End of variables declaration//GEN-END:variables

}
